import BigInteger from './biginteger';

// Modular reduction using "classic" algorithm
// tslint:disable-next-line:max-classes-per-file
export default class Classic {
	constructor(protected m: BigInteger) { }
	public convert(x: BigInteger) {
		if (x.s < 0 || x.compareTo(this.m) >= 0) {
			return x.mod(this.m);
		} else {
			return x;
		}
	}
	public revert(x: BigInteger) {
		return x;
	}
	public reduce(x: BigInteger) {
		x.divRemTo(this.m, null, x);
	}
	public mulTo(x: BigInteger, y: BigInteger, r: BigInteger) {
		x.multiplyTo(y, r);
		this.reduce(r);
	}
	public sqrTo(x: BigInteger, r: BigInteger) {
		x.squareTo(r);
		this.reduce(r);
	}
}

